using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace TVSGPP.func
{
	public class frmSearchBill : Form
	{
		private IContainer components = null;
		private GroupBox groupBox1;
		private Label label1;
		private TextBox txtBillID;
		private TextBox txtProductName;
		private Label label2;
		private ComboBox cbbProvider;
		private Label label5;
		private Button btnSearch;
		private Button btnClose;
		private TextBox txtPacket;
		private Label label3;
		private TextBox txtBarCode;
		private Label label4;
		private Func objFunc = new Func();
		public string tmpStrConnection = "";
		public string sql_Search = "";
		public string type_Input = "";
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmSearchBill));
			this.groupBox1 = new GroupBox();
			this.txtBarCode = new TextBox();
			this.label4 = new Label();
			this.txtPacket = new TextBox();
			this.label3 = new Label();
			this.cbbProvider = new ComboBox();
			this.label5 = new Label();
			this.txtProductName = new TextBox();
			this.label2 = new Label();
			this.txtBillID = new TextBox();
			this.label1 = new Label();
			this.btnSearch = new Button();
			this.btnClose = new Button();
			this.groupBox1.SuspendLayout();
			base.SuspendLayout();
			this.groupBox1.Controls.Add(this.txtBarCode);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.txtPacket);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.cbbProvider);
			this.groupBox1.Controls.Add(this.label5);
			this.groupBox1.Controls.Add(this.txtProductName);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.txtBillID);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new Point(7, 3);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(470, 139);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Thông tin tìm kiếm";
			this.txtBarCode.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.txtBarCode.Location = new Point(308, 56);
			this.txtBarCode.Name = "txtBarCode";
			this.txtBarCode.Size = new Size(153, 22);
			this.txtBarCode.TabIndex = 2;
			this.label4.AutoSize = true;
			this.label4.Location = new Point(247, 59);
			this.label4.Name = "label4";
			this.label4.Size = new Size(57, 15);
			this.label4.TabIndex = 14;
			this.label4.Text = "Mã vạch :";
			this.txtPacket.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.txtPacket.Location = new Point(308, 26);
			this.txtPacket.Name = "txtPacket";
			this.txtPacket.Size = new Size(153, 22);
			this.txtPacket.TabIndex = 4;
			this.txtPacket.KeyPress += new KeyPressEventHandler(this.txtPacket_KeyPress);
			this.label3.AutoSize = true;
			this.label3.Location = new Point(236, 29);
			this.label3.Name = "label3";
			this.label3.Size = new Size(68, 15);
			this.label3.TabIndex = 13;
			this.label3.Text = "Số hiệu lô :";
			this.cbbProvider.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.cbbProvider.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbbProvider.FormattingEnabled = true;
			this.cbbProvider.Location = new Point(101, 86);
			this.cbbProvider.Name = "cbbProvider";
			this.cbbProvider.Size = new Size(360, 23);
			this.cbbProvider.TabIndex = 5;
			this.cbbProvider.KeyPress += new KeyPressEventHandler(this.cbbProvider_KeyPress);
			this.label5.AutoSize = true;
			this.label5.Location = new Point(9, 90);
			this.label5.Name = "label5";
			this.label5.Size = new Size(89, 15);
			this.label5.TabIndex = 12;
			this.label5.Text = "Nhà cung cấp :";
			this.txtProductName.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.txtProductName.Location = new Point(101, 56);
			this.txtProductName.Name = "txtProductName";
			this.txtProductName.Size = new Size(130, 22);
			this.txtProductName.TabIndex = 1;
			this.txtProductName.KeyPress += new KeyPressEventHandler(this.txtProductName_KeyPress);
			this.label2.AutoSize = true;
			this.label2.Location = new Point(5, 59);
			this.label2.Name = "label2";
			this.label2.Size = new Size(93, 15);
			this.label2.TabIndex = 2;
			this.label2.Text = "Tên sản phẩm :";
			this.txtBillID.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.txtBillID.Location = new Point(101, 26);
			this.txtBillID.Name = "txtBillID";
			this.txtBillID.Size = new Size(130, 22);
			this.txtBillID.TabIndex = 3;
			this.txtBillID.KeyPress += new KeyPressEventHandler(this.txtBillID_KeyPress);
			this.label1.AutoSize = true;
			this.label1.Location = new Point(14, 29);
			this.label1.Name = "label1";
			this.label1.Size = new Size(84, 15);
			this.label1.TabIndex = 0;
			this.label1.Text = "Số đơn hàng :";
			this.btnSearch.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnSearch.FlatStyle = FlatStyle.Flat;
			this.btnSearch.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnSearch.Location = new Point(294, 151);
			this.btnSearch.Name = "btnSearch";
			this.btnSearch.Size = new Size(90, 26);
			this.btnSearch.TabIndex = 6;
			this.btnSearch.Text = "Tìm kiếm";
			this.btnSearch.UseVisualStyleBackColor = true;
			this.btnSearch.Click += new EventHandler(this.btnSearch_Click);
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new Point(387, 151);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(90, 26);
			this.btnClose.TabIndex = 7;
			this.btnClose.Text = "Thoát [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.White;
			base.ClientSize = new Size(484, 186);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.btnSearch);
			base.Controls.Add(this.groupBox1);
			this.Cursor = Cursors.Hand;
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			this.MaximumSize = new Size(500, 220);
			this.MinimumSize = new Size(500, 220);
			base.Name = "frmSearchBill";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = " ..: TÌM KIẾM";
			base.Load += new EventHandler(this.frmSearchBill_Load);
			base.KeyDown += new KeyEventHandler(this.frmSearchBill_KeyDown);
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			base.ResumeLayout(false);
		}
		public frmSearchBill()
		{
			this.InitializeComponent();
			this.tmpStrConnection = this.objFunc.strConnectionString;
		}
		private void frmSearchBill_Load(object sender, EventArgs e)
		{
			this.getObject();
			this.txtProductName.Focus();
		}
		private void getObject()
		{
			DataTable dataTable = new DataTable();
			DataColumn column = new DataColumn("ID", typeof(string));
			DataColumn column2 = new DataColumn("Name", typeof(string));
			dataTable.Columns.Add(column);
			dataTable.Columns.Add(column2);
			dataTable.Rows.Add(new object[]
			{
				"TVS0",
				"CHỌN ĐỐI TƯỢNG CỦA HOÁ ĐƠN"
			});
			SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
			string cmdText;
			if (this.type_Input == "IN")
			{
				cmdText = "SELECT [CusID] , UPPER(Name) AS Name FROM [TabPartner] WHERE [ISProvider] = 1";
			}
			else
			{
				cmdText = "SELECT [CusID] , UPPER(Name) AS Name FROM [TabPartner] WHERE [IsCustomer] = 1";
			}
			SqlCommand sqlCommand = new SqlCommand(cmdText, sqlConnection);
			sqlConnection.Open();
			SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
			while (sqlDataReader.Read())
			{
				if (this.type_Input == "IN")
				{
					dataTable.Rows.Add(new object[]
					{
						sqlDataReader["CusID"].ToString(),
						sqlDataReader["Name"].ToString()
					});
				}
				else
				{
					dataTable.Rows.Add(new object[]
					{
						sqlDataReader["CusID"].ToString(),
						sqlDataReader["Name"].ToString()
					});
				}
			}
			sqlDataReader.Close();
			sqlConnection.Close();
			sqlConnection.Dispose();
			this.cbbProvider.DataSource = dataTable;
			this.cbbProvider.DisplayMember = "Name";
			this.cbbProvider.ValueMember = "ID";
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void btnSearch_Click(object sender, EventArgs e)
		{
			if (this.type_Input == "IN")
			{
				this.sql_Search = "SELECT DISTINCT [TabBill].[ID], [TabBill].[CreateDate], [TabBill].[TotalMoney], [TabBill].[TypeInput], [TabBill].[WID], [TabBill].[Note], [TabBill].[PID], [TabBill].[userName], [TabBill].[Printed], [TabBill].[Discount] FROM [TabBill],[TabDetailBill] WHERE [TabBill].[ID] = [TabDetailBill].[BillID] AND [TabBill].[TypeInput] IN ('IN1','IN2','IN3')";
			}
			else
			{
				this.sql_Search = "SELECT DISTINCT [TabBill].[ID], [TabBill].[CreateDate], [TabBill].[TotalMoney], [TabBill].[TypeInput], [TabBill].[WID], [TabBill].[Note], [TabBill].[PID], [TabBill].[userName], [TabBill].[Printed], [TabBill].[Discount] FROM [TabBill],[TabDetailBill] WHERE [TabBill].[TotalMoney] > 0 AND [TabBill].[ID] = [TabDetailBill].[BillID] AND [TabBill].[TypeInput] IN ('OUT1','OUT2','OUT3')";
			}
			if (this.txtBillID.Text != "")
			{
				this.sql_Search = this.sql_Search + " AND ([TabBill].[ID] = '" + this.txtBillID.Text + "'";
			}
			else
			{
				this.sql_Search += " AND (1 = 1";
			}
			if (this.txtPacket.Text != "")
			{
				this.sql_Search = this.sql_Search + " AND UPPER([TabDetailBill].[Packet]) = '" + this.txtPacket.Text.ToUpper() + "'";
			}
			else
			{
				this.sql_Search += " AND 1 = 1";
			}
			if (this.txtProductName.Text != "")
			{
				this.sql_Search = this.sql_Search + " AND [TabDetailBill].[productName] LIKE N'%" + this.txtProductName.Text + "%'";
			}
			else
			{
				this.sql_Search += " AND 1 = 1";
			}
			if (this.cbbProvider.SelectedValue.ToString() != "TVS0")
			{
				this.sql_Search = this.sql_Search + " AND [TabBill].[PID] = '" + this.cbbProvider.SelectedValue.ToString() + "')";
			}
			else
			{
				this.sql_Search += " AND 1 = 1)";
			}
			if (this.txtBarCode.Text != "")
			{
				string text = this.sql_Search;
				this.sql_Search = string.Concat(new string[]
				{
					text,
					" AND ([TabDetailBill].[Barcode] = '",
					this.txtBarCode.Text,
					"' OR [TabDetailBill].[Barcode] = '0",
					this.txtBarCode.Text,
					"')"
				});
			}
			else
			{
				this.sql_Search += " AND 1 = 1";
			}
			if (this.txtBarCode.Text.Trim() != "" || this.txtBillID.Text.Trim() != "" || this.txtProductName.Text.Trim() != "" || this.cbbProvider.SelectedValue.ToString() != "TVS0" || this.txtPacket.Text.Trim() != "")
			{
				base.Close();
			}
			else
			{
				MessageBox.Show("Bạn chưa cung cấp thông tin cần tìm kiếm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}
		private void txtBillID_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.txtPacket.Focus();
			}
		}
		private void txtProductName_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.cbbProvider.Focus();
			}
		}
		private void cbbProvider_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.btnSearch.PerformClick();
			}
		}
		private void txtPacket_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\r')
			{
				this.txtProductName.Focus();
			}
		}
		private void frmSearchBill_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}
	}
}
